/////////////////////////////////////////////////////////////////////////////
// Name:        mainform.hpp
// Purpose:     
// Author:      Erwan Le Martelot
// Modified by: 
// Created:     23/04/2007 11:36:18
// RCS-ID:      
// Copyright:   
// Licence:     
/////////////////////////////////////////////////////////////////////////////

#ifndef _MAINFORM_H_
#define _MAINFORM_H_

#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma interface "mainform.hpp"
#endif

/*!
 * Includes
 */

////@begin includes
#include "wx/frame.h"
#include "wx/splitter.h"
#include "wx/glcanvas.h"
#include "wx/tglbtn.h"
#include "wx/listctrl.h"
#include "wx/spinctrl.h"
////@end includes

// ----- My Includes ----- //
#include "SCDisplayFrame.hpp"
#include "SCProgram.hpp"
#include "SCEngine.hpp"
#include "SystemsDialog.hpp"
#include <string>
#include <vector>
#include <utility>
#include "Samples.hpp"
#include "wxVectorIndexedPlotCurve.hpp"
// ----------------------- //

/*!
 * Forward declarations
 */

////@begin forward declarations
class wxMenu;
class wxSplitterWindow;
class SCDisplayFrame;
class wxToggleButton;
class wxListView;
class wxPlotWindow;
class wxSpinCtrl;
////@end forward declarations

/*!
 * Control identifiers
 */

////@begin control identifiers
#define ID_MAINFORM 10000
#define ID_LOAD_PROGRAM_MENUITEM 10023
#define ID_LOAD_DATA_MENUITEM 10027
#define ID_SAVE_DATA_MENUITEM 10029
#define ID_EXPORT_RESULTS_MENUITEM 10034
#define ID_QUIT_MENUITEM 10035
#define ID_PLUGIN_DIR_MENUITEM 10002
#define ID_MAIN_SPLITTERWINDOW 10008
#define ID_LEFT_PANEL 10006
#define ID_LOAD_PROGRAM_BUTTON 10009
#define ID_SCDISPLAYFRAME 10001
#define ID_RUN_TOGGLEBUTTON 10010
#define ID_RESET_BUTTON 10016
#define ID_SHOW_SYSTEMS_BUTTON 10012
#define ID_RIGHT_PANEL 10007
#define ID_ADD_SET_BUTTON 10011
#define ID_REMOVE_SET_BUTTON 10020
#define ID_CLEAR_SET_BUTTON 10024
#define ID_RESET_SET_RESULTS_BUTTON 10022
#define ID_SETS_LISTVIEW 10018
#define ID_SAMPLES_PANEL 10026
#define ID_ADD_SAMPLES_BUTTON 10030
#define ID_REMOVE_SAMPLES_BUTTON 10032
#define ID_CLEAR_SAMPLES_BUTTON 10033
#define ID_CLASS_SAMPLES_TEXTCTRL 10037
#define ID_SAMPLES_LISTVIEW 10025
#define ID_PLOTWINDOW 10015
#define ID_IPS_SPINCTRL 10004
#define ID_LEARN_SPIKE_SPINCTRL 10013
#define ID_DISPLAY_CHECKBOX 10031
#define ID_DISP_BUF_SPINCTRL 10005
#define ID_PROCESS_TOGGLEBUTTON 10003
#define ID_MAX_EPOCHS_SPINCTRL 10014
#define ID_BATCH_RADIOBUTTON 10017
#define ID_ONLINE_RADIOBUTTON 10019
#define SYMBOL_MAINFORM_STYLE wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxMINIMIZE_BOX|wxMAXIMIZE_BOX|wxCLOSE_BOX
#define SYMBOL_MAINFORM_TITLE _("SC Artificial Neural Networks")
#define SYMBOL_MAINFORM_IDNAME ID_MAINFORM
#define SYMBOL_MAINFORM_SIZE wxSize(1000, 650)
#define SYMBOL_MAINFORM_POSITION wxDefaultPosition
////@end control identifiers

/*!
 * Compatibility
 */

#ifndef wxCLOSE_BOX
#define wxCLOSE_BOX 0x1000
#endif

/*!
 * MainForm class declaration
 */

class MainForm: public wxFrame
{    
	DECLARE_CLASS( MainForm )
	DECLARE_EVENT_TABLE()

public:
	/// Constructors
	MainForm();
	MainForm( wxWindow* parent, wxWindowID id = SYMBOL_MAINFORM_IDNAME, const wxString& caption = SYMBOL_MAINFORM_TITLE, const wxPoint& pos = SYMBOL_MAINFORM_POSITION, const wxSize& size = SYMBOL_MAINFORM_SIZE, long style = SYMBOL_MAINFORM_STYLE );

	bool Create( wxWindow* parent, wxWindowID id = SYMBOL_MAINFORM_IDNAME, const wxString& caption = SYMBOL_MAINFORM_TITLE, const wxPoint& pos = SYMBOL_MAINFORM_POSITION, const wxSize& size = SYMBOL_MAINFORM_SIZE, long style = SYMBOL_MAINFORM_STYLE );

	/// Destructor
	~MainForm();

	/// Initialises member variables
	void Init();

	/// Creates the controls and sizers
	void CreateControls();

////@begin MainForm event handler declarations

	/// wxEVT_SIZE event handler for ID_MAINFORM
	void OnSize( wxSizeEvent& event );

	/// wxEVT_IDLE event handler for ID_MAINFORM
	void OnIdle( wxIdleEvent& event );

	/// wxEVT_COMMAND_MENU_SELECTED event handler for ID_LOAD_PROGRAM_MENUITEM
	void OnLoadProgramMenuitemClick( wxCommandEvent& event );

	/// wxEVT_COMMAND_MENU_SELECTED event handler for ID_LOAD_DATA_MENUITEM
	void OnLoadDataMenuitemClick( wxCommandEvent& event );

	/// wxEVT_COMMAND_MENU_SELECTED event handler for ID_SAVE_DATA_MENUITEM
	void OnSaveDataMenuitemClick( wxCommandEvent& event );

	/// wxEVT_COMMAND_MENU_SELECTED event handler for ID_EXPORT_RESULTS_MENUITEM
	void OnExportResultsMenuitemClick( wxCommandEvent& event );

	/// wxEVT_COMMAND_MENU_SELECTED event handler for ID_QUIT_MENUITEM
	void OnQuitMenuitemClick( wxCommandEvent& event );

	/// wxEVT_COMMAND_MENU_SELECTED event handler for ID_PLUGIN_DIR_MENUITEM
	void OnPluginDirMenuitemClick( wxCommandEvent& event );

	/// wxEVT_COMMAND_MENU_SELECTED event handler for wxID_ABOUT
	void OnAboutClick( wxCommandEvent& event );

	/// wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED event handler for ID_MAIN_SPLITTERWINDOW
	void OnMainSplitterwindowSashPosChanged( wxSplitterEvent& event );

	/// wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_LOAD_PROGRAM_BUTTON
	void OnLoadProgramButtonClick( wxCommandEvent& event );

	/// wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_RUN_TOGGLEBUTTON
	void OnRunTogglebuttonClick( wxCommandEvent& event );

	/// wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RESET_BUTTON
	void OnResetButtonClick( wxCommandEvent& event );

	/// wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_SHOW_SYSTEMS_BUTTON
	void OnShowSystemsButtonClick( wxCommandEvent& event );

	/// wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_ADD_SET_BUTTON
	void OnAddSetButtonClick( wxCommandEvent& event );

	/// wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_REMOVE_SET_BUTTON
	void OnRemoveSetButtonClick( wxCommandEvent& event );

	/// wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_CLEAR_SET_BUTTON
	void OnClearSetButtonClick( wxCommandEvent& event );

	/// wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RESET_SET_RESULTS_BUTTON
	void OnResetSetResultsButtonClick( wxCommandEvent& event );

	/// wxEVT_COMMAND_LIST_ITEM_SELECTED event handler for ID_SETS_LISTVIEW
	void OnSetsListviewSelected( wxListEvent& event );

	/// wxEVT_COMMAND_LIST_ITEM_DESELECTED event handler for ID_SETS_LISTVIEW
	void OnSetsListviewDeselected( wxListEvent& event );

	/// wxEVT_COMMAND_LIST_END_LABEL_EDIT event handler for ID_SETS_LISTVIEW
	void OnSetsListviewEndLabelEdit( wxListEvent& event );

	/// wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_ADD_SAMPLES_BUTTON
	void OnAddSamplesButtonClick( wxCommandEvent& event );

	/// wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_REMOVE_SAMPLES_BUTTON
	void OnRemoveSamplesButtonClick( wxCommandEvent& event );

	/// wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_CLEAR_SAMPLES_BUTTON
	void OnClearSamplesButtonClick( wxCommandEvent& event );

	/// wxEVT_COMMAND_TEXT_UPDATED event handler for ID_CLASS_SAMPLES_TEXTCTRL
	void OnClassSamplesTextctrlUpdated( wxCommandEvent& event );

	/// wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_DISPLAY_CHECKBOX
	void OnDisplayCheckboxClick( wxCommandEvent& event );

	/// wxEVT_COMMAND_SPINCTRL_UPDATED event handler for ID_DISP_BUF_SPINCTRL
	void OnDispBufSpinctrlUpdated( wxSpinEvent& event );

	/// wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_PROCESS_TOGGLEBUTTON
	void OnProcessTogglebuttonClick( wxCommandEvent& event );

////@end MainForm event handler declarations

////@begin MainForm member function declarations

	/// Retrieves bitmap resources
	wxBitmap GetBitmapResource( const wxString& name );

	/// Retrieves icon resources
	wxIcon GetIconResource( const wxString& name );
////@end MainForm member function declarations

	/// Should we show tooltips?
	static bool ShowToolTips();

////@begin MainForm member variables
	wxMenu* fileMenu;
	wxSplitterWindow* mainSplitter;
	wxStaticText* progNameLabel;
	wxButton* loadButton;
	wxStaticText* nbSysLabel;
	wxStaticText* nbCtxLabel;
	SCDisplayFrame* displayFrame;
	wxToggleButton* runToggleButton;
	wxButton* resetButton;
	wxButton* showSystemsButton;
	wxButton* addSetsButton;
	wxButton* removeSetsButton;
	wxButton* clearSetsButton;
	wxStaticText* setsType;
	wxStaticText* setsSize;
	wxListView* setsListView;
	wxPanel* samplesPanel;
	wxButton* addSamplesButton;
	wxButton* removeSamplesButton;
	wxButton* clearSamplesButton;
	wxStaticText* samplesNumber;
	wxTextCtrl* samplesClassification;
	wxListView* samplesListView;
	wxPlotWindow* setPlot;
	wxSpinCtrl* ipsSpinCtrl;
	wxSpinCtrl* learnSpikeSpinCtrl;
	wxCheckBox* displayCheckBox;
	wxSpinCtrl* dspBufSpinCtrl;
	wxStaticText* epochNbLabel;
	wxStaticText* sampleNbLabel;
	wxStaticText* curSetLabel;
	wxStaticText* curInputLabel;
	wxToggleButton* processToggleButton;
	wxSpinCtrl* maxSupEpochsSpinCtrl;
	wxRadioButton* batchRadioButton;
	wxStaticText* learningStateLabel;
protected:
	SC::SCProgram program;
	wxImageList * sysColourList;
	SC::SCEngine engine;
	std::vector<std::string> plugin_dirs;
	SystemsDialog * systems_dialog;
	std::vector<Toolkit::SampleSet> sets;
	unsigned int sampleNb;
	std::pair<int,int> current_sample;
	unsigned int iter_counter;
	std::vector<wxToolkit::wxVectorIndexedPlotCurve *> outputCurves;
	std::vector<wxToolkit::wxVectorIndexedPlotCurve *> classCurves;
	std::vector< std::pair<int,int> > epoch;
	unsigned int epochNb;
////@end MainForm member variables
	void loadProgram();
	//wxImage drawSystemImage(const unsigned char, const unsigned char, const unsigned char);
	void resetVariables();
	void resetFields();
	void updateProcessButton();
	void setSetsStatistics();
	void setSampleList();
};

#endif
	// _MAINFORM_H_
